package cse326.fuellog;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ExtendedHistory extends Activity
{

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_extended_history);
		
		Intent intent = getIntent();
		int vehicleID = Integer.parseInt(intent.getStringExtra("vehicleID"));
		
		LinkedList <Fillup> fillups = MainActivity.getFillupsByVehicle(MainActivity.db,MainActivity.getVehicles(MainActivity.db).get(vehicleID));
		
		TextView o = (TextView)findViewById(R.id.extendedhistory_area);
		
		o.setText(null);
		SimpleDateFormat df = new SimpleDateFormat();
		Date d = new Date();
		
		for (Fillup f:fillups)
		{
			d.setTime(f.getDate());

			// Change the pattern here if wanted.
			df.applyPattern("M-d-yy HH:mm");

			// Add it to the TextArea
			o.append(df.format(d) + ": " + f.getGallons() + " @ $" + f.getGasPrice() + ", " + (double)Math.round(f.getMPG() * 1000) / 1000 + "mpg\n");

		}
	}
	
	public void back(View view){
		finish();
	}


}
